package cate.game.play.buff;

import cate.common.table.fight.buff.row.BuffRow;
import cate.common.util.SplitParser;
import cate.common.util.XT;
import cate.game.attr.FightAttr;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.config.PlayCfgUtil;
import cate.game.play.config.buff.ExBuffCfg;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

@NoteClass("buff强化配置")
public class BuffEnhanceCfg {

	@NoteField("目标buff")
	private List<Integer> tarBuffIds;

	@NoteField("目标原型")
	private List<Integer> tarProtoIds;

	@NoteField("目标标签")
	private List<String> tarTags;

	@NoteField("目标类型")
	private List<String> tarEffectTypes;

	@NoteField("附加概率")
	public int exAddChance;

	@NoteField("附加属性")
	public FightAttr exAttr;

	@NoteField("附加回合")
	public Integer exRound;

	@NoteField("附加最大数量")
	public Integer exPileMax;

	@NoteField("能否驱散")
	public Boolean dispel;

	@NoteField("无视抗控")
	public Boolean ignAntiCtrl;

	@NoteField("血量")
	public Long buffHp;

	@NoteField("附加效果配置")
	public String exEffectArgs;

	@NoteField("附加buff")
	public List<ExBuffCfg> exBuffs;

	//目标buff=123#223&目标原型=？？#？？&目标标签=??#??&目标类型=??#??
	//附加概率=10000&附加属性=1:100&附加回合=1&附加最大数量=1&
	//能否驱散=0&无视抗控=0&血量=0&
	//附加效果配置=开始回合_1|结束回合_2
	//附加buff=2:123:10000
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		tarBuffIds = args.getIntList("目标buff");
		tarProtoIds = args.getIntList("目标原型");
		tarTags = args.getStrList("目标标签");
		tarEffectTypes = args.getStrList("目标类型");

		exAddChance = args.getInt("附加概率", 0);
		String attrStr = args.get("附加属性");
		if (StringUtils.isNotBlank(attrStr)) {
			exAttr = new FightAttr(attrStr);
		}
		exRound = args.getInt("附加回合", null);
		exPileMax = args.getInt("附加最大数量", null);
		dispel = args.getBoolean("能否驱散", null);
		ignAntiCtrl = args.getBoolean("无视抗控", null);
		buffHp = args.getLong("血量", null);
		exEffectArgs = PlayCfgUtil.replaceExCode(args.get("附加效果配置"));

		exBuffs = SplitParser.parse(ExBuffCfg.class, args.get("附加buff"));
	}

	public boolean test(BuffRow row) {
		if (XT.isNotBlank(tarBuffIds) && !tarBuffIds.contains(row.id)) {
			return false;
		}
		if (XT.isNotBlank(tarProtoIds) && !tarProtoIds.contains(row.protoId)) {
			return false;
		}
		if (XT.isNotBlank(tarTags) && !row.containTags(tarTags)) {
			return false;
		}
		if (XT.isNotBlank(tarEffectTypes) && !tarEffectTypes.contains(row.effectType)) {
			return false;
		}
		return true;
	}

}
